package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "套餐相关接口")
@Slf4j
@RequestMapping("/admin/setmeal")


public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @PostMapping
    @ApiOperation("新增菜品接口")
    @CacheEvict(cacheNames = "setmealCache",key = "#setmealDTO.categoryId")
    public Result add(@RequestBody SetmealDTO setmealDTO){
      setmealService.add(setmealDTO);
        return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation("套餐分页显示")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
       PageResult pageResult= setmealService.page(setmealPageQueryDTO);
        return Result.success(pageResult);

    }
    @DeleteMapping()
    @ApiOperation("批量删除套餐")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result deletemeal(@RequestParam List<Long> ids){
        setmealService.delete(ids);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    @ApiOperation("套餐售卖状态")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result startorstop(@PathVariable Integer status,Long id){
       setmealService.update(status,id);
        return Result.success();
    }
@GetMapping("/{id}")
    @ApiOperation("根据id搜索套餐")
    public Result<SetmealVO> selectmealbyid(@PathVariable Long id){
        SetmealVO setmealVO =setmealService.selectbyid(id);
        return Result.success(setmealVO);
}
@PutMapping()
    @ApiOperation("修改套餐")
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result updatemeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.updatemeal(setmealDTO);
        return Result.success();
}

}
